package com.lx.es.query.test.controller;

import cn.lx.es.query.search.entity.PageList;
import com.lx.es.query.test.dto.DrugSearchDTO;
import com.lx.es.query.test.service.DrugSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 药品搜索控制器
 *
 * @author test
 * @date 2025-01-02
 */
@RestController
@RequestMapping("/api/drugs")
public class DrugSearchController {

    @Autowired
    private DrugSearchService drugSearchService;

    /**
     * 按药品名称搜索
     */
    @GetMapping("/search/name")
    public PageList<DrugSearchDTO> searchByDrugName(@RequestParam String drugName) {
        return drugSearchService.searchByDrugName(drugName);
    }

    /**
     * 按生产企业搜索
     */
    @GetMapping("/search/manufacturer")
    public PageList<DrugSearchDTO> searchByManufacturer(@RequestParam String manufacturer) {
        return drugSearchService.searchByManufacturer(manufacturer);
    }

    /**
     * 按剂型搜索
     */
    @GetMapping("/search/dosage-form")
    public PageList<DrugSearchDTO> searchByDosageForm(@RequestParam String dosageForm) {
        return drugSearchService.searchByDosageForm(dosageForm);
    }

    /**
     * 按药理分类搜索
     */
    @GetMapping("/search/pham-type")
    public PageList<DrugSearchDTO> searchByPhamType(@RequestParam String phamTypes) {
        return drugSearchService.searchByPhamType(phamTypes);
    }

    /**
     * 按日均使用量范围搜索
     */
    @GetMapping("/search/day-use-range")
    public PageList<DrugSearchDTO> searchByDayUseRange(
            @RequestParam Double minDayUse,
            @RequestParam Double maxDayUse) {
        return drugSearchService.searchByDayUseRange(minDayUse, maxDayUse);
    }

    /**
     * 复杂搜索
     */
    @GetMapping("/search/complex")
    public PageList<DrugSearchDTO> complexSearch(
            @RequestParam(required = false) String drugName,
            @RequestParam(required = false) String manufacturer,
            @RequestParam(required = false) String dosageForm) {
        return drugSearchService.complexSearch(drugName, manufacturer, dosageForm);
    }

    /**
     * 搜索基药
     */
    @GetMapping("/search/essential")
    public PageList<DrugSearchDTO> searchEssentialDrugs() {
        return drugSearchService.searchEssentialDrugs();
    }

    /**
     * 搜索医保药品
     */
    @GetMapping("/search/medical-insurance")
    public PageList<DrugSearchDTO> searchMedicalInsuranceDrugs() {
        return drugSearchService.searchMedicalInsuranceDrugs();
    }

    /**
     * 自定义搜索
     */
    @PostMapping("/search/custom")
    public PageList<DrugSearchDTO> customSearch(@RequestBody DrugSearchDTO searchDTO) {
        return drugSearchService.searchDrugs(searchDTO);
    }
}
